package com.github.thinwonton.springboot.showcase.multidatasource.service;


import com.github.thinwonton.springboot.showcase.multidatasource.config.DS;
import com.github.thinwonton.springboot.showcase.multidatasource.config.DatabaseType;
import com.github.thinwonton.springboot.showcase.multidatasource.dao.AccountDao;
import com.github.thinwonton.springboot.showcase.multidatasource.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * AccountService
 *
 * @author hugo
 * @date 2018/8/22
 */
@Service
public class AccountService {
    @Autowired
    private AccountDao accountDao;

    @DS(DatabaseType.ACCOUNT)
    @Transactional(rollbackFor = Exception.class)
    public void createAccount() {
        Account account = new Account();
        account.setAccountId(String.valueOf(System.currentTimeMillis()));
        account.setMoney(new BigDecimal(30.9));
        accountDao.insert(account);
    }

}
